package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.PrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @auther falls_vc
 * description:
 * @date 2025/5/21  20:54
 */
@Mapper
public interface PrizeMapper {
    /**
     * 插入奖品信息
     * 填入自增生成的奖品id
     * @param prizeDO
     * @return
     */
    @Insert("insert into prize(name,image_url,price,description) values (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int insert(PrizeDO prizeDO);

    @Select("select count(1) from prize")
    Integer count();

    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);

    @Select("<script> select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')' > " +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistIdsByIds(@Param("items") List<Long> ids);

    @Select("<script> select * from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')' > " +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> prizeIds);

    @Select("select * from prize where id=#{prizeId}")
    PrizeDO selectById(@Param("prizeId") Long prizeId);
}
